package com.gzc.pm.ro;

import java.util.List;

import cn.skyclass.net.OperationResult;

import com.gzc.pm.bean.DetsetbBean;
import com.gzc.pm.bean.ToleranceBean;
import com.gzc.pm.dao.DetsetbDao;
import com.gzc.pm.dao.ToleranceDao;

public class ToleranceRo {

	public List<ToleranceBean> getInProcIds(String procIdsStr){
		ToleranceDao dao = new ToleranceDao();
		return dao.getInProcIds(procIdsStr);
	}
	
	public OperationResult insertOrUpdateTolerance(int procId, DetsetbBean detsetb, float usl, float lsl){
		DetsetbDao detsetbDao = new DetsetbDao();
		ToleranceDao toleranceDao = new ToleranceDao();
		OperationResult result = OperationResult.SUCCESS;
		
//		List<EquconBean> equconList = equconDao.getByProcId(procId);//工序下所有检测项
//		for(EquconBean bean : equconList){
//			if(equcon.getEquKeyV().equals(bean.getEquKeyV())){
//				int equcId = bean.getEqucId();
//				ToleranceBean tolerance = toleranceDao.getByEqucId(equcId);
//				if(tolerance == null){
//					tolerance = new ToleranceBean();
//					tolerance.setEqucId(equcId);
//					tolerance.setUsl(usl);
//					tolerance.setLsl(lsl);
//					result = toleranceDao.insert(tolerance);
//				}else{
//					tolerance.setUsl(usl);
//					tolerance.setLsl(lsl);
//					result = toleranceDao.update(tolerance);
//				}
//				if(!result.isSuccessful()) return result;
//			}
//		}
		int detsetbId = detsetb.getDetsIdb();
		ToleranceBean tolerance = toleranceDao.getByEqucId(detsetbId);
		if(tolerance == null){
			tolerance = new ToleranceBean();
			tolerance.setEqucId(detsetbId);
			tolerance.setUsl(usl);
			tolerance.setLsl(lsl);
			result = toleranceDao.insert(tolerance);
		}else{
			tolerance.setUsl(usl);
			tolerance.setLsl(lsl);
			result = toleranceDao.update(tolerance);
		}
		if(!result.isSuccessful()) return result;
		
		return result;
	}
}
